package cn.elead.chaos.remote.web.remote.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.elead.chaos.core.util.DateUtil;
import cn.elead.chaos.remote.web.remote.domain.SysNotice;
import cn.elead.chaos.remote.web.remote.mapper.SysNoticeMapper;
import cn.elead.chaos.remote.web.remote.service.ISysNoticeService;
import cn.elead.chaos.sso.core.util.SsoUtils;

/**
 * 公告 服务层实现
 * 
 * @author luopeng
 */
@Service
public class SysNoticeServiceImpl implements ISysNoticeService {

	@Autowired
	private SysNoticeMapper noticeMapper;

	/**
	 * 查询公告信息
	 * 
	 * @param noticeId 公告ID
	 * @return 公告信息
	 */
	@Override
	public SysNotice selectNoticeById(Long noticeId) {
		return noticeMapper.selectNoticeById(noticeId);
	}

	/**
	 * 查询公告列表
	 * 
	 * @param notice 公告信息
	 * @return 公告集合
	 */
	@Override
	public List<SysNotice> selectNoticeList(SysNotice notice) {
		notice.setTenant(SsoUtils.getTenant());
		return noticeMapper.selectNoticeList(notice);
	}

	/**
	 * 新增公告
	 * 
	 * @param notice 公告信息
	 * @return 结果
	 */
	@Override
	public int insertNotice(SysNotice notice) {
		notice.setTenant(SsoUtils.getTenant());
		notice.setCreateTime(DateUtil.date());
		notice.setCreateBy(SsoUtils.getUserName());
		notice.setUpdateTime(DateUtil.date());
		notice.setUpdateBy(SsoUtils.getUserName());
		return noticeMapper.insertNotice(notice);
	}

	/**
	 * 修改公告
	 * 
	 * @param notice 公告信息
	 * @return 结果
	 */
	@Override
	public int updateNotice(SysNotice notice) {
		notice.setUpdateTime(DateUtil.date());
		notice.setUpdateBy(SsoUtils.getUserName());
		return noticeMapper.updateNotice(notice);
	}

	/**
	 * 删除公告对象
	 * 
	 * @param noticeId 公告ID
	 * @return 结果
	 */
	@Override
	public int deleteNoticeById(Long noticeId) {
		return noticeMapper.deleteNoticeById(noticeId);
	}

	/**
	 * 批量删除公告信息
	 * 
	 * @param noticeIds 需要删除的公告ID
	 * @return 结果
	 */
	public int deleteNoticeByIds(Long noticeIds) {
		return noticeMapper.deleteNoticeByIds(noticeIds);
	}
}
